package com.course.service.impl;

import com.course.entity.ResultBody;
import com.course.mapper.RegisterMapper;
import com.course.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RegisterServiceImpl implements RegisterService {
    @Autowired
    private RegisterMapper registerMapper;

    //检验用户名是否重复
    @Override
    public int ReUserName(String username){
        if(registerMapper.ReUserName(username)!=null)
            return 1;
        else
            return 0;
    }

    //检验电话号码是否重复
    @Override
    public int  ReUserPhone(String userphone)
    {
        if(registerMapper.ReUserPhone(userphone)!=null)
            return 1;
        else
            return 0;
    }
    //数据满足条件向下传递
    @Override
    public ResultBody AddUser(String username,String userphone,String userpassword,String usernumber,String role)
    {
        if(registerMapper.AddUser(username,userphone,userpassword,usernumber,role)>0)
        {
            return new ResultBody(200,"注册成功",true);
        }
        else
            return new ResultBody(400,"注册失败",false);
    }
    @Override
    public int checkPhoneNumber(String phonenumber)
    {
        if(registerMapper.checkPhoneNumber(phonenumber) ==null)
        {
            return 0;
        }
        else
            return 1;
    }
    @Override
    public int checkEmail(String email)
    {
        if(registerMapper.checkEmail(email) ==null)
            return 0;
        else
            return 1;
    }
    @Override
    public  int  checkUserName(String username)
    {
        if(registerMapper.checkUserName(username) ==null)
        {
            return 0;
        }
        return 1;
    }
    //增加用户
    @Override
    public  int RegisterUser(String username, String password1,String  phonenumber, String email)
    {
        if(registerMapper.RegisterUser (username,  password1, phonenumber, email)==1)
            return 1;
        else
            return 0;
    }

}
